package com.stn.zjx.givingtreasure.glide;

import android.content.Context;
import android.support.annotation.NonNull;

import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.load.engine.cache.MemorySizeCalculator;
import com.bumptech.glide.module.AppGlideModule;

import java.util.Objects;

/**
 * Created by 朱俊鑫 on 2018
 * glide初始化自定义配置
 * @author 朱俊鑫
 * @since 2018-3
 * @property cacheSize 最大缓存10M
 */
@SuppressWarnings("deprecation")
@GlideModule
public class MyGlideModule extends AppGlideModule {
     private long cacheSize;

    public MyGlideModule() {
        cacheSize = 10*1024*1024L;
    }

    //配置图片加载参数
    @Override
    public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
        super.applyOptions(context, builder);
        //存储缓存路径下的glide目录
        builder.setDiskCache(new DiskLruCacheFactory(Objects.requireNonNull(context.getExternalCacheDir()).getPath(),"glide",cacheSize));
        MemorySizeCalculator calucator=new  MemorySizeCalculator.Builder(context)
                .setMemoryCacheScreens(2F)
                .build();
        builder.setMemoryCache(new LruResourceCache(calucator.getMemoryCacheSize()));
    }

    //禁止解析xml中的配置
    @Override
    public boolean isManifestParsingEnabled() {
        return  false;
    }




}
